#include "A.h"

#define eps 0.0001
#define M 1000

double t(double x)
{
    return x*PI/180;
}

class Function : public Fun
{
private:
    double A, B, C, D, E;
    double alpha, beta, l, h;
public:
    Function(double _beta, double _l, double _h, double _D):
    beta(_beta), l(_l), h(_h), D(_D)
    {
        A = l*sin(beta);
        B = l*cos(beta);
        C = (h+0.5*D)*sin(beta)-0.5*D*tan(beta);
        E = (h+0.5*D)*cos(beta)-0.5*D;
    }
    double f(double x)
    {
        return A*sin(x)*cos(x)+B*sin(x)*sin(x)-C*cos(x)-E*sin(x);
    }
    double df(double x)
    {
        return A*cos(2*x)+2*B*sin(x)*cos(x)+C*sin(x)-E*cos(x);
    }
};

double testa()
{
    Function fa(t(11.5), 89, 49, 55);
    Newton s(fa, t(33), eps, M);
    return s.solve()*180/PI;
}

double testb()
{
    Function fa(t(11.5), 89, 49, 30);
    Newton s(fa, t(33), eps, M);
    return s.solve()*180/PI;
}

double testc1()
{
    Function fa(t(11.5), 89, 49, 30);
    Secant s(fa, t(33), t(60), eps, eps, M);
    return s.solve()*180/PI;
}

double testc2()
{
    Function fa(t(11.5), 89, 49, 30);
    Secant s(fa, t(160), t(180), eps, eps, M);
    return s.solve()*180/PI;
}

int main()
{
	printf("The solution is %f\n",testa());
	printf("The solution is %f\n",testb());
	printf("The solution is %f with the initial value 33 and 60 degrees\n",testc1());
    printf("The solution is %f with the initial value 160 and 180 degrees\n",testc2());
}